let query_item_name = '';
let query_item_stater = '';
let app = new Vue({
	el:'.app',
	data:{
		title:'查询条件',
		name:'物品名称',
		state:'库存状态',
		query_btn:'查询',
		total:'',
		pageSize:5,
		pageNumber:1,
		add_disappear:false,
		// 添加
		item_name:'',
		item_price:'',
		item_format:'',
		item_total:'',
		item_inventory:'',
		// 修改
		updata_id:'',
		updata_name:'',
		updata_price:'',
		updata_format:'',
		updata_total:'',
		updata_inventory:'',
		updata_disappear:false,
		// 查询
		query_name1:'',
		query_stater1:'',
		// 删除
		ids:[],
		list:[]
	},
	created:function(){
		this.getlist()
	},
	computed:{
		pagenum:function(){
			return Math.ceil(this.total/this.pageSize)
		}
	},
	methods:{
		getlist:function(){
			axios.get('http://chonghekj.com/crud/index.php/Home/Index/getItemList',{
				params:{
					pageSize:this.pageSize,
					pageNumber:this.pageNumber,
					item_name:this.query_name1,
					item_state:this.query_stater1
				}
			})
			.then((res) => {
				this.list = res.data.rows;
				this.total = res.data.total
			})
		},
		getpagelist:function(){
			this.pageNumber = 1;
			this.getlist()
		},
		getPageNumber:function(pageNumber){
			this.pageNumber = pageNumber;
			this.getlist()
		},
		getaddbox:function(){
			this.add_disappear = true
		},
		cancel:function(){
			this.add_disappear = false
		},
		// 添加
		determine:function(){
			axios.post('http://chonghekj.com/crud/index.php/Home/Index/addItem', Qs.stringify({
				item_name:this.item_name,
				item_price:this.item_price,
				item_format:this.item_format,
				item_total:this.item_total,
				item_inventory:this.item_inventory
			}))
			.then((res) => {
				this.add_disappear = false
				this.getlist()
			})
		},
		// 修改
		updata_cancel:function(){
			this.updata_disappear = false
		},
		updatabox:function(){
			if(this.ids.length == '1'){
				this.updata_disappear = true
			}else{
				alert('请勿多选')
			}
		},
		updata:function(item){
			this.updata_id = item.item_id,
			this.updata_name = item.item_name,
			this.updata_price = item.item_price,
			this.updata_format = item.item_format,
			this.updata_total = item.item_total,
			this.updata_inventory = item.item_inventory
		},
		updata_determine:function(){
			axios.post('http://chonghekj.com/crud/index.php/Home/Index/editItem',Qs.stringify({
				item_id : this.updata_id,
				item_name : this.updata_name,
				item_price : this.updata_price,
				item_format : this.updata_format,
				item_total : this.updata_total,
				item_inventory : this.updata_inventory
			}))
			.then((res) => {
				this.updata_disappear = false
				this.getlist()
			})
		},
		// 查询
		querybtn:function(){
			query_item_name = this.query_name1
			query_item_stater = this.query_stater1
			this.getlist()
		},
		// 删除
		deledata:function(){
			if(this.ids.length == 0){
				alert('请选择删除的内容')
			}else{
				axios.post('http://chonghekj.com/crud/index.php/Home/Index/deleteItem',Qs.stringify({
					ids:this.ids
				}))
				.then((res) => {
					this.getlist()
					ids = []
				})
			}
		}
	}
})